home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt40s2.arc / MYLOADO.MOD < prev    next >
Text File  |  1987-04-23  |  10KB  |  228 lines

  1. (*----------------------------------------------------------------------*)
  2. (*         MyLoadOverlay --- Load Turbo Extender overlay without abort  *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. FUNCTION MyLoadOverlay( OverlaySection: INTEGER;
  6.                         ModuleNumber  : INTEGER;
  7.                         FileName      : AnyStr   ) : BOOLEAN;
  8.  
  9. (*----------------------------------------------------------------------*)
  10. (*                                                                      *)
  11. (*     Function:   MyLoadOverlay                                        *)
  12. (*                                                                      *)
  13. (*     Purpose:    Loads Turbo Extender overlay if found                *)
  14. (*                                                                      *)
  15. (*     Calling Sequence:                                                *)
  16. (*                                                                      *)
  17. (*        Found := MyLoadOverlay( OverlaySection: INTEGER;              *)
  18. (*                                ModuleNumber  : INTEGER;              *)
  19. (*                                FileName      : AnyStr   ) : BOOLEAN; *)
  20. (*                                                                      *)
  21. (*           OverlaySection --- Overlay section to load module into     *)
  22. (*           ModuleNumber   --- Module number to be loaded              *)
  23. (*           FileName       --- Chain file name containing module code  *)
  24. (*                                                                      *)
  25. (*           Found          --- TRUE if module found                    *)
  26. (*                                                                      *)
  27. (*     Remarks:                                                         *)
  28. (*                                                                      *)
  29. (*        This routine tries to load an overlay file.  If it exists,    *)
  30. (*        MyLoadOverlay is returned TRUE.  If it is not found, a brief  *)
  31. (*        message is printed, and MyLoadOverlay is returned FALSE.      *)
  32. (*                                                                      *)
  33. (*        Note:  Overlay sections 0 and 1 are real overlay sections.    *)
  34. (*                                                                      *)
  35. (*----------------------------------------------------------------------*)
  36.  
  37. VAR
  38.    Ch        : CHAR;
  39.    I         : INTEGER;
  40.    ModNo     : INTEGER;
  41.    S         : AnyStr;
  42.  
  43. BEGIN (* MyLoadOverlay *)
  44.                                    (* If this module is already loaded, *)
  45.                                    (* we don't need to reload it.       *)
  46.    LoadingOverlay := FALSE;
  47.  
  48.    IF ( ABS( ModuleLoaded[ModuleNumber] ) = OverlaySection ) THEN
  49.       BEGIN
  50.          MyLoadOverlay := TRUE;
  51.       END
  52.    ELSE
  53.       BEGIN
  54.                                    (* See if overlay file exists *)
  55.  
  56.          IF ( NOT ExistFile( FileName , S ) ) THEN
  57.             BEGIN
  58.                                    (* If not, display message and return *)
  59.  
  60.                MyLoadOverlay := FALSE;
  61.  
  62.                IF Attended_Mode THEN
  63.                   BEGIN
  64.                      WRITELN;
  65.                      WRITELN('Cannot load ',FileName,'.');
  66.                      Press_Any;
  67.                      WRITELN;
  68.                   END;
  69.  
  70.             END
  71.          ELSE
  72.             BEGIN
  73.                                    (* Otherwise, load it.                *)
  74.                ModNo := -1;
  75.  
  76.                FOR I := 1 TO MaxNumModules DO
  77.                   IF ( ModuleLoaded[I] = OverlaySection ) THEN
  78.                      ModNo := I;
  79.  
  80.                                    (* Unload modules from heap, but *)
  81.                                    (* leave modules loaded in EMM   *)
  82.  
  83.                IF ( ModNo > 0 ) THEN
  84.                   WITH BigModules[ModNo] DO
  85.                      IF ( Handle = NOTInEMS ) THEN
  86.                         BEGIN
  87.                            UnLoadModule( ModNo );
  88.                            ModuleLoaded[ModNo] := -99;
  89.                         END
  90.                      ELSE
  91.                         ModuleLoaded[ModNo] := ( -OverlaySection );
  92.  
  93.                                    (* Set up overlay load if needed *)
  94.  
  95.                IF ( NOT Use_EMM_For_Overlays ) THEN
  96.                   IF ( OverlaySection < 2 ) THEN
  97.                      BEGIN (* Set up overlay load to RAM *)
  98.                         LoadingOverlay   := TRUE;
  99.                         GlobalOverlayNum := OverlaySection;
  100.                      END;
  101.                                    (* Load the module! *)
  102.  
  103.                LoadModule( ModuleNumber , FileName , Use_EMM_For_Overlays );
  104.  
  105.                LoadingOverlay := FALSE;
  106.                MyLoadOverlay  := TRUE;
  107.  
  108.                                    (* Mark this module as loaded *)
  109.  
  110.                ModuleLoaded[ModuleNumber] := OverlaySection;
  111.  
  112.             END;
  113.  
  114.       END;
  115.                                    (* Make sure all resident code updated *)
  116.  
  117.    CloneCodeSegment( TurboRunDataStart , TurboRunDataLength );
  118.  
  119. END   (* MyLoadOverlay *);
  120.  
  121. (*----------------------------------------------------------------------*)
  122. (*         UnloadEmulator --- Unload terminal emulation module          *)
  123. (*----------------------------------------------------------------------*)
  124.  
  125. PROCEDURE UnloadEmulator;
  126.  
  127. (*----------------------------------------------------------------------*)
  128. (*                                                                      *)
  129. (*     Function:   UnloadEmulator                                       *)
  130. (*                                                                      *)
  131. (*     Purpose:    Unloads terminal emulation module if loaded          *)
  132. (*                                                                      *)
  133. (*     Calling Sequence:                                                *)
  134. (*                                                                      *)
  135. (*        UnloadEmulator;                                               *)
  136. (*                                                                      *)
  137. (*----------------------------------------------------------------------*)
  138.  
  139. VAR
  140.    ModNo: INTEGER;
  141.  
  142. BEGIN (* UnloadEmulator *)
  143.  
  144.    FOR Modno := 1 TO MaxNumModules DO
  145.       IF ( ModuleLoaded[ModNo] = 2 ) THEN
  146.          WITH BigModules[ModNo] DO
  147.             IF ( Handle = NOTInEMS ) THEN
  148.                BEGIN
  149.                   UnLoadModule( ModNo );
  150.                   ModuleLoaded[ModNo] := -99;
  151.                END
  152.             ELSE
  153.                ModuleLoaded[ModNo] := ( -2 );
  154.  
  155. END   (* UnloadEmulator *);
  156.  
  157. (*----------------------------------------------------------------------*)
  158. (*    MyGetOverlayArea --- Set up overlay area (not standard Extender)  *)
  159. (*----------------------------------------------------------------------*)
  160.  
  161. PROCEDURE MyGetOverlayArea( OverlaySection: INTEGER;
  162.                             FileName      : AnyStr;
  163.                             OSize         : INTEGER );
  164.  
  165. (*----------------------------------------------------------------------*)
  166. (*                                                                      *)
  167. (*     Procedure:  MyGetOverlayArea                                     *)
  168. (*                                                                      *)
  169. (*     Purpose:    Set up non-standard overlay area                     *)
  170. (*                                                                      *)
  171. (*     Calling Sequence:                                                *)
  172. (*                                                                      *)
  173. (*        MyGetOverlayArea( OverlaySection: INTEGER;                    *)
  174. (*                          FileName      : AnyStr;                     *)
  175. (*                          OSize         : INTEGER );                  *)
  176. (*                                                                      *)
  177. (*           OverlaySection --- Overlay section to initialize           *)
  178. (*           FileName       --- Chain file name containing module code  *)
  179. (*           OSize          --- Size of area to allocate if 'FileName'  *)
  180. (*                              is null.                                *)
  181. (*                                                                      *)
  182. (*     Remarks:                                                         *)
  183. (*                                                                      *)
  184. (*        This routine adds simple overlay stuff to the EMS version     *)
  185. (*        of Turbo Extender, which doesn't have overlays.  This is not  *)
  186. (*        a very general implementation.                                *)
  187. (*                                                                      *)
  188. (*        Note:  Overlay sections 0 and 1 are real overlay sections.    *)
  189. (*                                                                      *)
  190. (*----------------------------------------------------------------------*)
  191.  
  192. VAR
  193.    F            : FILE;
  194.    FirstRunJump : INTEGER ABSOLUTE CSeg : $101;
  195.    FileSize     : INTEGER;
  196.    RuntimeSize  : INTEGER;
  197.  
  198. BEGIN (* MyGetOverlayArea *)
  199.                                    (* Get size of runtime library in bytes, *)
  200.                                    (* including PSP                         *)
  201.  
  202.     RuntimeSize := FirstRunJump + $103;
  203.  
  204.                                    (* Find file and get the file size *)
  205.  
  206.     IF( LENGTH( FileName ) > 0 ) THEN
  207.        BEGIN
  208.           FileSize := ReturnFileInfo( FileName , F );
  209.           CLOSE( F );
  210.        END
  211.     ELSE
  212.        FileSize := OSize;
  213.                                    (* Check if new size same as old.  If so *)
  214.                                    (* no need to reallocate memory.         *)
  215.  
  216.     WITH OverlayArea[OverlaySection] DO
  217.        BEGIN
  218.  
  219.           Size          := FileSize + RuntimeSize + $20;
  220.  
  221.           GETMEM( Pointer , Size );
  222.  
  223.           OverlaySeg    := SUCC( Seg( Pointer^ ) );
  224.           CurrentModule := -1;
  225.  
  226.        END;
  227.  
  228. END   (* MyGetOverlayArea *);